﻿

namespace Cos.Module.Blog.NHibernate.Test
{
    using System;
    using System.Collections.Generic;

    using Cos.Core.NHibernate;
    using Cos.Core.NHibernate.Tests;

    using FluentNHibernate;

    using NUnit.Framework;

    public class BlogFixtureBase : FixtureBase
    {
        public BlogDataModel Blog { get; private set; }
        public ArticleDataModel Article { get; private set; }
        public CultureDataModel Culture { get; private set; }
        public ArticleCultureDataModel ArticleCulture { get; private set; }
        public BlogCultureDataModel BlogCulture { get; private set; }
        public CommentDataModel Comment { get; private set; }
        public TagDataModel Tag { get; private set; }

        public BlogFixtureBase()
            : base(new TestModel())
        {
            this.Blog = new BlogDataModel
            {
                CreationDate = new DateTime(2011, 01, 03),
                OwnerId = Guid.NewGuid(),
                OwnerFirstName = "Bill",
                OwnerLastName = "Smith"
            };

            this.Article = new ArticleDataModel
            {
                CreationDate = new DateTime(2011, 03, 04)
            };

            this.Culture = new CultureDataModel
            {
                Id = "En-US",
                CultureDesc = string.Empty,
                IsDefault = true
            };

            this.ArticleCulture = new ArticleCultureDataModel
            {
                Author = "author test",
                AuthorFirstName = "Bill",
                AuthorId = "1234",
                AuthorLastName = "Tee",
                LastModified = new DateTime(2000, 01, 01),
                Text = "text test",
                Title = "title test",
                CultureCode = "En-US"
            };

            this.BlogCulture = new BlogCultureDataModel
                {
                    CultureCode = "En-US",
                    LastModified = new DateTime(2005, 01, 01),
                    Text = "Lolll",
                    Title = "breeeee"
                };

            this.Comment = new CommentDataModel
                {
                    ArticleCultureId = this.ArticleCulture.Id,
                    AuthorFirstName = "Nicole",
                    AuthorId = "333",
                    AuthorLastName = "Junk",
                    CreationDate = new DateTime(2000, 01, 01),
                    LastModified = new DateTime(2009, 01, 01),
                    Text = "tttttt",
                    Title = "null"
                };

            this.Tag = new TagDataModel
                {
                    CultureCode = this.Culture.Id,
                    Name = "test"
                };
        }

        [TestFixtureSetUp]
        public void BlogFixtureSetupContext()
        {
            using (var tx = this.Session.BeginTransaction())
            {
                this.Session.SaveOrUpdate(this.Culture);
                this.Session.SaveOrUpdate(this.Blog);
                this.Article.BlogId = this.Blog.Id;
                this.BlogCulture.BlogId = this.Blog.Id;

                this.Session.SaveOrUpdate(this.Article);
                this.ArticleCulture.ArticleId = this.Article.Id;

                this.Session.SaveOrUpdate(this.ArticleCulture);
                this.Session.SaveOrUpdate(this.Tag);

                tx.Commit();
            }

            this.Session.Flush();
            this.Session.Clear();
        }
    }
}
